﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proggy.Web.Cms.Core.Configuration;

namespace Proggy.Web.Cms.Core.ViewModels
{
    /// <summary>
    /// View model
    /// </summary>
    public class AddDragAndDropPartViewModel
    {
        public string AllowedPartsString { get; set; }
        public List<DragAndDropPartElement> AllowedParts
        {
            get
            {
                // get array
                string[] arr = null;
                if (AllowedPartsString.Contains(","))
                {

                    arr = this.AllowedPartsString.Split(',');

                }
                else {
                    arr = new string[] { AllowedPartsString };
                }

                // start output
                var output = new List<DragAndDropPartElement>();

                // iterate and add
                foreach (var allowed in arr) { 
                    output.Add(DragAndDropManager.DragAndDropPartsCache.Single(x=>x.Name==allowed));
                }

                // return output
                return output;
            }
        }
    }
}
